package com.ld.admin.utils;

import java.lang.reflect.Field;
import java.util.HashMap;
import java.util.Map;

import com.ld.admin.model.system.outdatabase.OutDatabaseExcelModel;
import com.ld.shieldsb.common.core.reflect.FunctionUtil;
import com.ld.shieldsb.common.core.reflect.FunctionUtil.Property;
import com.ld.shieldsb.common.core.reflect.ModelUtil;

import cn.afterturn.easypoi.excel.annotation.Excel;

public class ExportUtil {
    private static final Map<Property<?, ?>, String> FUNCTION_NAMES = new HashMap<>(); // Property和显示名称的对应缓存

    /**
     * 获取Excel导出名称
     * 
     * @Title getFiledExcelShowName
     * @author 吕凯
     * @date 2019年8月20日 上午9:34:16
     * @param property
     * @return String
     */
    public static <T> String getFiledExcelShowName(Property<T, ?> property) {
        String objShowName = FUNCTION_NAMES.get(property);
        if (objShowName == null) {
            Field field = ModelUtil.getField(OutDatabaseExcelModel.class, FunctionUtil.getFunctionName(property));
            if (field != null) {
                objShowName = field.getName();
                cn.afterturn.easypoi.excel.annotation.Excel descriptionAnno = field.getAnnotation(Excel.class);
                if (descriptionAnno != null) {
                    objShowName = descriptionAnno.name();
                }
            }
        }
        return objShowName;
    }

}
